<%@page import="model.Room"%>
<%@page import="model.AvailableRoom" %>
<%@page import="model.Booking" %>
<%@page import="dao.impl.BookingDaoImpl" %>
<%@page import="dao.intf.BookingDao" %>
<%@page import="dao.impl.RoomDaoImpl"%>
<%@page import="dao.intf.RoomDao" %>
<%@page import="dao.impl.AvailableRoomDaoImpl"%>
<%@page import="dao.intf.AvailableRoomDao" %>
<%@page import="java.util.ArrayList" %>
<%@page import="java.util.List" %>
<%@page import="java.util.*" %>
<%@page import="model.RoomType"%>
<%@page import="dao.impl.RoomTypeDaoImpl"%>
<%@page import="dao.intf.RoomTypeDao" %>



<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML>
<html>
<head>
    <title>Hotel Arbour : Search Booking </title>
    <script src="js/jquery-1.9.1.js" language="javascript"></script>
	<script src="js/jquery-ui-1.10.2.custom.js" language="javascript"></script>
	<script type="text/javascript" src="js/post_watermarkinput.js"></script>
	<link rel="stylesheet" href="CSS/ui-lightness/jquery-ui-1.10.2.custom.css" type="text/css">
	<link href="CSS/vasplus_programming_blog_CSS.css" rel="stylesheet" type="text/css">
	
<script>
	$(function() {
		$( "#accordion" ).accordion();	
		
		var date = new Date();
		var currentYear = date.getFullYear();
		var currentMonth = date.getMonth();
		var currentDate = date.getDate();
		currentDate2 = date.getDate() + 1;
		
		$("#checkindate").datepicker({
			onSelect: function (date) {
				if ($("#checkindate").val() != '' && $("#checkoutdate").val() != ''){
					var start = $('#checkindate').datepicker('getDate');
				    var end = $('#checkoutdate').datepicker('getDate');
				    var diff = (end - start)/1000/60/60/24;
					$("#night").val(diff);
					//alert(diff);
				}            
	        },
			dateFormat: "yy-mm-dd",
			minDate:new Date(currentYear, currentMonth, currentDate)
		});
		
		$("#checkoutdate").datepicker({
			onSelect: function (date) {
				if ($("#checkindate").val() != '' && $("#checkoutdate").val() != ''){
					var start = $('#checkindate').datepicker('getDate');
				    var end = $('#checkoutdate').datepicker('getDate');
				    var diff = (end - start)/1000/60/60/24;
					$("#night").val(diff);
					//alert(diff);
				}
	            
	        },
			dateFormat: "yy-mm-dd",
			minDate:new Date(currentYear, currentMonth, currentDate2)		
		});
		
	});	
	
	
</script>
<script>
$(document).ready(function() { 
	
	
    $('#btnRates').click(function(event) { 
    	
    	var msg = '';
    	if ($('#checkindate').val() == '') 
			msg = msg + 'Please select Check In date.\n';
    	if ($('#checkoutdate').val() == '') 
			msg = msg  + 'Please select Check Out date.\n';	
    	if ($('#adult').val() == '' )
			msg = msg  + 'Please enter number of Adult(s).\n';
		if ($('#children').val() == '' )
			msg = msg  + 'Please enter number of Children.\n';
		if (parseInt($('#night').val()) < 1 )
			msg = msg  + 'Checkin date must be earlier than Checkout date.\n';	
		
		if (msg != '' ) alert (msg);
		else{
			$('#action').val('checkrates');
			$('#checkrates').val('1');
			$('#frmSearch').submit();
		}//end else
    	
    });
});
$(document).ready(function() { 
	
	
    $('#btnSearch').click(function(event) { 
    	
    	
    	var msg = '';
    	  	if ($('#bookingno').val() == '' && $('#bookingemail').val() == '') 
			msg = msg  + 'Please enter Search Criteria.\n';
		
		if (msg != '' ) alert (msg);
		else{
			$('#action').val('search');
			$('#frmSearch').submit();
		}//end else
    	
    });
});
$(document).ready(function(){	
	
	//$('#availability').attr('style' , 'display:none');
	$('#rooms').keypress(function(event){		
		if (event.charCode > 31 && (event.charCode < 48 || event.charCode > 57)) {
			return false;
		}
	}); 
	$('#adult').keypress(function(event){		
		if (event.charCode > 31 && (event.charCode < 48 || event.charCode > 57)) {
			return false;
		}
	});
	$('#children').keypress(function(event){		
		if (event.charCode > 31 && (event.charCode < 48 || event.charCode > 57)) {
			return false;
		}		
	});
	$('#night').keypress(function(event){		
		if (event.charCode > 31 && (event.charCode < 48 || event.charCode > 57)) {
			return false;
		}
	});	
});


	
</script>



</head>
<body style="font-family:Calibri;">
<form action="BookingServlet" id="frmSearch" name="frmSearch" method="POST">	
	<div id="body" style="width:900px ;margin:0 auto; padding:0 0 0 0 auto;">
	
	<!-- Header-->		
		<input type="hidden" value="" name="checkrates" id="checkrates">
		<table width="100%" border="0px" cellpadding="0">
		<tr>
			<td><img src="images/logo.jpg" /></td>
			
			<td colspan="2">
				<p align="right" style="font-weight:bold;">			
					<a href="index.jsp" style="text-decoration:none;"><font style="color:#7E354D">Home&nbsp;&nbsp;|&nbsp;&nbsp;</font></a>
					<a href="index.jsp" style="text-decoration:none;"><font style="color:#7E354D">Promotion&nbsp;&nbsp;|&nbsp;&nbsp;</font></a>
					<a href="index.jsp" style="text-decoration:none;"><font style="color:#7E354D">Rooms&nbsp;&nbsp;&nbsp;</font></a>						
				</p> 
				<p align="right" style="font-weight:bold;">
					<div id="login_response"></div>	
				</p>					
				
			</td>
		</tr>
        <tr>
            <td style="width:65%;vertical-align:top;">
				<video width="600" height="260" controls>
				<source src="movie.mp4" type="images/Sample.mp4"></source></video>
				
            </td>
			
            <td style="width:35%;vertical-align:top;"> 
				<table border="0px" width="100%">
					<tr>
					    <td>
					        <div id="accordion">	
                                 <h1 style="border:1px solid #7E354D;"><font style="color:#7E354D">Reservation</font></h1>
					                <div>
					                    <table>
					                    <%
									   		
										%>
											<tr>
												<td>Check-In:</td>
												<td><input type="text" id="checkindate" name="checkindate" readonly="readonly" value=''/></td>
											</tr>
											<tr>
												<td>Check-Out:</td>
												<td><input type="text" id="checkoutdate" name="checkoutdate" value=''/></td></tr>
											<tr>
												<td>Room Type:</td>												
											    <td><select name="roomtype" id="roomtype">
											    	<option value='All'>--- All Room ---</option>
											    	<%
														
												    	List<RoomType> roomTypeList = new ArrayList<RoomType>();
												    	RoomTypeDaoImpl roomTypeDaoObj = new dao.impl.RoomTypeDaoImpl();
												    	roomTypeList = roomTypeDaoObj.getRoomTypeList();
												    	
												    	for (int i = 0 ; i < roomTypeList.size() ; i ++){	
															out.println("<option value='"+roomTypeList.get(i).getId()+"'>" + roomTypeList.get(i).getName() + "</option>");																
														}	
													%>                                                   
                                                </select>&nbsp;
                                                 
                                                </td>
											</tr>																						
											<tr>
												<td colspan="2" align="center">
													Rooms:&nbsp;&nbsp;Adult:&nbsp;&nbsp;Children:&nbsp;&nbsp;Nights:
													<br><input type="text" id="rooms" name="rooms" size="2" maxlength="3" value=''/>&nbsp;
													&nbsp;&nbsp;<input type="text" id="adult" name="adult" size="3" maxlength="3" value=''/>&nbsp;
													<input type="text" id="children" name="children" size="3" maxlength="1" value=''/> 
													&nbsp;&nbsp;<input type="text" id="night" name="night" size="2" maxlength="3" value=''/>&nbsp;
														
												</td>
											</tr>											
											
											<tr>
												<td colspan="2" align="center">
													<input type="button" id="btnRates" value="Check Rates"/>&nbsp;
													<a href="search.jsp" style="text-decoration:none;"><font style="color:#7E354D">View&nbsp;|&nbsp;</font></a>
													<a href="search.jsp" style="text-decoration:none;"><font style="color:#7E354D">Modify&nbsp;|&nbsp;</font></a> 
													<a href="search.jsp" style="text-decoration:none;"><font style="color:#7E354D">Cancel&nbsp;</font></a>
												</td>
											</tr>
										</table>
                                    </div> 
                                     <h1 style="border:1px solid #7E354D;"><font style="color:#7E354D">Corporate Login</font></h1>
					                <div>
										<table>
											<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
											
											<tr><td>Login ID:</td><td><input type="text" id="emailLogin" name="emailLogin" size="10"/></td></tr>
											<tr><td>Password:</td><td><input type="text" id="pswLogin" name="pswLogin" size="10"/></td></tr>
											<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
											<tr><td>&nbsp;</td><td><input type="button" id="btnLogin" name="btnLogin" value="Log In" onclick="login();"/>&nbsp;
																	<input type="button" id="signup" name="signup" value="Sign Up" onclick="toggleDiv();"/></td></tr>
										</table>
                                    </div>                                 
					        </div>
					    </td>
					</tr>					
				</table>
			</td>
        </tr>
    </table>

    <!-- Header-->	
	<!-- Search Reservation-->
	<br><br>
	<%
	String shide = "";
	String lhide = "display:none"; 
	String msghide = "display:none";
	List<Booking> BookingList = new ArrayList<Booking>();	
	if (request.getAttribute("bookinglist") != null) {						
		BookingList = (ArrayList)request.getAttribute("bookinglist");
		//out.println("Size in jsp "+ BookingList.size());
		if (BookingList.size() > 0) {			
			lhide = "";			
		}else {
			msghide = "";
		}
	} 
	%>
	<div id="searchReservation" style='<% out.println(shide); %>'>
		<table width="70%" align="center" style="font-size:15px;-khtml-border-radius: 20px;-moz-border-radius: 20px;-ms-border-radius: 20px;-o-border-radius: 20px;-webkit-border-radius: 20px;border-radius: 20px;
				border: solid 1px gray;" cellpadding="5px">
			<tr>
				<td colspan="2">&nbsp;
				<div id="nobookingmsg" name="nobookingmsg" style='<% out.println(msghide); %>' >
					<font color="red">**Sorry, there are no reservations that meet your search criteria.</font>
					
				</div></td>
			</tr>
			<tr><td>Booking No : </td><td><input type="text" id="bookingno" name="bookingno" size="50"/></td></tr>
			<tr><td>Email : </td><td><input type="text" id="bookingemail" name="bookingemail" size="50"/></td></tr>
			
			<tr>
				<td colspan="2" align="center"><input type="button" id="btnSearch" value="Search"/></td>
			</tr>
			<tr>
				<td colspan="2" text-align="left">
					<!-- Booking History-->
				
			   <div id="searchList" width="70px" align="center" style='<% out.println(lhide); %>'>
					<br><br>
					<%
					if (BookingList.size() > 0){
						
						String disabled = "";
						Date today = new Date();
						//if (BookingList.get(0).getId() != null ) bookingid = BookingList.get(0).getId();			
						String tblCss = "";
						for (int i = 0 ; i < BookingList.size() ; i ++){			
							//if (BookingList.get(i).getStart().compareTo(today) < 1) {
								//disabled = "disabled='disabled'";
							//}
								if (i%2 != 0){
									tblCss = "'background-color:#fdf5ce;border-top: 1px solid;'";
								}else 
									tblCss = "'border-top: 1px solid;'";
				%>
					<table width="100%" border="0px" align="center" style=<%out.println(tblCss); %> cellrpadding="5px">	
						<tr>
							<td colspan="2" align="center">&nbsp;</td>
						</tr>
						<tr>
							<td>&nbsp;</td><td><b>Booking No. : <%out.println(BookingList.get(i).getId()); %></b></td> 	<td></td> 			
						</tr>
						<tr>
							<td>&nbsp;</td><td ><b>Arrival Date </b>  <%out.println(BookingList.get(i).getStart() + ""); %></td><td>&nbsp;</td><td ><b>Departure Date </b>: <%out.println(BookingList.get(i).getEnd() + ""); %></td>
							<td>
								<a href="viewdetail.jsp?bookingid=<% out.println(BookingList.get(i).getId());%>">
			    							View
								</a>
								
							</td>
						</tr>				
						<tr>
							<td colspan="2" align="center">&nbsp;</td>
						</tr>			
					</table>
				<%	}
						
					}  %>	
					<table width="70%" border="0px" align="center" cellrpadding="5px">	
						
						<tr>
							<td>&nbsp;</td> 			
						</tr>
									
									
					</table>
				</div>
	<!-- Booking History-->	
				</td>
			</tr>
		</table>
		<input type="hidden" value="" name="action" id="action" value="">
	</div>
	
	</div>   
</form>
</html>